define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        // 關懷圈選擇用戶
        caring_task_user: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/user/caring_task_user/ids/'+Config.ids,
                    add_url: 'user/user/add',
                    // edit_url: 'user/user/edit',
                    // del_url: 'user/user/del',
                    multi_url: 'user/user/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                searchFormVisible: true,
                search:false,
                showColumns:false,
                showExport:false,
                // commonSearch:false,
                showToggle: false,
                pageSize: 10,
                singleSelect: true, //是否启用单选
                // maintainSelected: true,
                columns: [
                    [
                        {field: 'state', checkbox: true,},
                        {field: 'id', title: __('Id'), sortable: true,operate:false},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'region_address', title: __('Region_address'), operate: false},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            table.on('load-success.bs.table', function () {
                // 默認選中
                $("#table").bootstrapTable("checkBy", {field:"id", values:Config.arr})
            });
            // 获取选中项
            $(document).on("click", ".btn-selected", function () {
                // data = JSON.stringify(Table.api.selecteddata(table));
                data = Table.api.selecteddata(table);
                // Layer.alert();
                Fast.api.close(data);//这里是重点
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});